package com.health.mapp.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

 

public class MappUtils {


	public static String toUni(String gbStr) {
		String uniStr = "";
		if (gbStr == null) {
			gbStr = "";
		}
		try {
			 byte[] tempByte = gbStr.getBytes("ISO-8859-1");
			//byte[] tempByte = gbStr.getBytes("GBK");
			uniStr = new String(tempByte, "UTF-8");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return uniStr;
	}
	
	//使用ArrayList实现一个Key对应一个ArrayList实现一对多
    public static <E> void putAdd(Map<String,ArrayList<E >> obj,String sr, Object s){
    	//System.out.println("s size:"+s.length);
    	//System.out.println("s  :"+s[0]);
    
    	//判断map是否有指定城市的key，如果没有，就新创建一个
        if(!obj.containsKey(sr)){
        	// System.out.println("我来创建了");
        	 obj.put(sr, (ArrayList<E>) new ArrayList<String>(10));
        }
        //现在将数据放到已创建的容器中
   	 	obj.get(sr).add((E) s);
       
        
        

	
    }
	public static String getCDRDataPath(String serviceNum) {
		String path = "";

		try {

			HashMap<String, String> config = MappGlobal.getInstance().getPropertiesConfig();
			String root = config.get("subscriber.cdrtask.root");

			long hashCode = 0;
			for (int i = 0; i < serviceNum.length(); i++) {
				hashCode = hashCode * 33 + Integer.valueOf(serviceNum.substring(i, i + 1));
			}
			String hash = String.valueOf(hashCode);

			long hash1 = Long.valueOf(hash.substring(0, hash.length() / 2)) % 100;
			long hash2 = Long.valueOf(hash.substring(hash.length() / 2)) % 100;
			path = String.format("%s/%03d/%03d/%s", root, hash1, hash2, serviceNum);

		} catch (Exception e) {
			e.printStackTrace();
		}

		return path;
	}

}
